package org.example;


import org.apache.hadoop.io.IntWritable;
//import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * Reduce 需要指定四个泛型，用来限定输入和输出的 key 和 value 的类型
 * 1、Map 的输出就是 Reduce 的输入
 * 2、Reduce 的输出是 <"java", 2>
 */
public class WordcountReducer extends Reducer<Text,IntWritable,Text,IntWritable> {
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        int sum = 0;
        for (IntWritable value : values){
            sum ++;
        }
        context.write(key,new IntWritable(sum));
    }
}
